package cn.tworice.admin.service.impl;

import cn.tworice.admin.dao.StudentDao;
import cn.tworice.admin.service.StudentService;
import cn.tworice.common.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;

    @Override
    public List<Student> getList(Integer page, Integer pageSize) {
        return studentDao.queryList((page * pageSize), pageSize);
    }

    @Override
    public Integer getTotal() {

        return studentDao.queryTotal();
    }

    @Override
    public void setStudent(Student student) {
        if (student.getId() == null || student.getId().isEmpty()) {
            student.setDate(System.currentTimeMillis());
            student.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            studentDao.insertStudent(student);
        }else{
            studentDao.updateStudent(student);
        }

    }

    @Override
    public void del(String id) {
        studentDao.del(id);
    }

    @Override
    public Student getStudentById(String id) {
        return studentDao.queryById(id);
    }
}
